﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace pwestcott.Util.Tests.Essence
{
    [TestFixture]
    public class ToStringTests
    {
        //[EssenceClass(UseIn = EssenceFunctions.All)]
        //class TestEssence
        //{
        //    [Essence(Order = 0, Format="x={0:000},")]
        //    public int MyInt;
        //    [Essence(Order = 1, Format="s='{0}',")]
        //    public string MyString;
        //    [Essence(Order = 2, Format="date=(0:yyyy-MM-dd)")]
        //    public DateTime MyDateTime;

        //    public override string ToString()
        //    {
        //        return "";
        //    }
        //}

        class TestManual : IFormattable
        {
            public int MyInt;
            public string MyString;
            public DateTime MyDateTime;

            public override string ToString()
            {
                return ToString(null, null);
            }

            public string ToString(string format, IFormatProvider formatProvider)
            {
                StringBuilder sb = new StringBuilder();

                sb.AppendFormat("x={0:000},", MyInt);
                sb.AppendFormat("s='{0}',", MyString);
                sb.AppendFormat("date={0:yyyy-MM-dd}", MyDateTime);

                return sb.ToString();
            }
        }

        [Test]
        public void FormattableTest()
        {
            var m = new TestManual();

            m.MyInt = 21;
            m.MyString = "Hello";
            m.MyDateTime = new DateTime(2009, 3, 21);

            var s = m.ToString("x={MyInt:000},s='{MyString}',date={MyDateTime:yyyy-MM-dd}", null);

            Assert.AreEqual("x=021,s='Hello',date=2009-03-21", s);
        }
    }
}
